﻿using System;
using System.Collections.Generic;

using Holdem.Core.Configuration;
using Holdem.Interfaces.Configuration;


using NUnit.Framework;

namespace Test.Holdem.Configuration
{
    [TestFixture]
    public class HoldemTestConfiguration
    {
        private const ConfigKey SAVE_CONFIG_KEY_DIR = ConfigKey.HandHistorySaveDirectory;
        private const string SAVE_DIR_CONFIG_KEY = "HandHistorySaveDirectory";

        [Ignore]
        private static string SaveDirectoryValue()
        {
            return "SaveDirectoryString." + DateTime.Now.Millisecond;
        }

        #region  HoldemAppSettings

        [Test]
        public void HoldemAppSettingsConstructor()
        {
            var dictionary = new Dictionary<string, object>();
            var settings = new HoldemAppSettings(dictionary);

            Assert.NotNull(settings);
        }

        [Test]
        public void HoldemAppSettingsSetGetConfigKeyIndexer()
        {
            var dictionary = new Dictionary<string, object>();
            var settings = new HoldemAppSettings(dictionary);

            var expected = SaveDirectoryValue();

            settings.Set(SAVE_CONFIG_KEY_DIR, expected);

            var save = settings[SAVE_CONFIG_KEY_DIR];

            Assert.AreEqual(expected, save);
        }

        [Test]
        public void HoldemAppSettingsSetGetKeyValueDefault()
        {
            var dictionary = new Dictionary<string, object>();
            var settings = new HoldemAppSettings(dictionary);

            var saveValue = SaveDirectoryValue();

            settings.Get(SAVE_CONFIG_KEY_DIR, saveValue);

            var save = settings[SAVE_CONFIG_KEY_DIR];

            Assert.AreEqual(saveValue, save);
        }

        [Test]
        public void HoldemAppSettingsSetGetKeyDefault()
        {
            var dictionary = new Dictionary<string, object>();
            var settings = new HoldemAppSettings(dictionary);

            settings.Get(SAVE_CONFIG_KEY_DIR);

            var save = settings.Get(SAVE_CONFIG_KEY_DIR);

            Assert.AreEqual(null, save);
        }

        [Test]
        public void HoldemAppSettingsConvertDictionary()
        {
            var dictionary = new Dictionary<string, object>();

            var expected = SaveDirectoryValue();

            dictionary.Add(SAVE_CONFIG_KEY_DIR.ToString(), expected);

            var settings = new HoldemAppSettings(dictionary);

            settings.Get(SAVE_CONFIG_KEY_DIR);

            var save = settings.Get(SAVE_CONFIG_KEY_DIR);

            Assert.AreEqual(expected, save);
        }

        //[Test]
        //public void HoldemAppSettingsConvertDictionaryInvalidKeyThrowsException()
        //{
        //    var dictionary = new Dictionary<string, object>();

        //    var expected = SaveDirectoryValue();

        //    dictionary.Add("InvalidConfigKey", expected);

        //    Assert.Throws<ArgumentException>( () => new HoldemAppSettings(dictionary) );
        //}

        [Test]
        public void HoldemAppSettingsSetGetStringIndexer()
        {
            var dictionary = new Dictionary<string, object>();
            var settings = new HoldemAppSettings(dictionary);

            var expected = SaveDirectoryValue();

            settings.Set(SAVE_CONFIG_KEY_DIR, expected);

            var save = settings[SAVE_CONFIG_KEY_DIR];

            Assert.AreEqual(expected, save);
        }

        //[Test]
        //public void HoldemAppSettingsSetGetStringIndexerDefault()
        //{
        //    var dictionary = new Dictionary<string, object>();
        //    var settings = new HoldemAppSettings(dictionary);

        //    var save = settings[SAVE_CONFIG_KEY_DIR];

        //    Assert.AreEqual(string.Empty, save);
        //}

        [Test]
        public void HoldemAppSettingsSetGetStringDefault()
        {
            var dictionary = new Dictionary<string, object>();
            var settings = new HoldemAppSettings(dictionary);

            var saveValue = SaveDirectoryValue();

            settings.Get(SAVE_CONFIG_KEY_DIR, saveValue);

            var save = settings[SAVE_CONFIG_KEY_DIR];

            Assert.AreEqual(save, saveValue);
        }

        [Test]
        public void HoldemAppSettingsSave()
        {
            var dictionary = new Dictionary<string, object>();
            var settings = new HoldemAppSettings(dictionary);

            settings.Set(SAVE_CONFIG_KEY_DIR, SaveDirectoryValue());

            Assert.Throws<NotImplementedException>(settings.Save);
        }

        //[Test]
        //public void HoldemAppSettingsRemove()
        //{
        //    var dictionary = new Dictionary<string, object>();
        //    var settings = new HoldemAppSettings(dictionary);

        //    var saved = SaveDirectoryValue();

        //    settings.Set(SAVE_CONFIG_KEY_DIR, saved);

        //    var result = settings.Remove(SAVE_CONFIG_KEY_DIR);

        //    var retrieved = settings[SAVE_CONFIG_KEY_DIR];

        //    Assert.IsTrue(result);
        //    Assert.AreEqual(string.Empty, retrieved);
        //}

        //[Test]
        //public void HoldemAppSettingsGetEnumerator()
        //{
        //    var dictionary = new Dictionary<string, object>();
        //    var settings = new HoldemAppSettings(dictionary);

        //    settings.Set(SAVE_CONFIG_KEY_DIR, SaveDirectoryValue());
        //    settings.Save();

        //    var enumerator = settings.GetEnumerator();

        //    Assert.IsNotNull(enumerator);
        //}

        [Test]
        public void HoldemAppSettingsHasKeyConfigKeyTrue()
        {
            var dictionary = new Dictionary<string, object>();
            var settings = new HoldemAppSettings(dictionary);

            settings.Set(SAVE_CONFIG_KEY_DIR, SaveDirectoryValue());

            var hasKey = settings.ContainsKey(SAVE_CONFIG_KEY_DIR);

            Assert.AreEqual(true, hasKey);
        }

        [Test]
        public void HoldemAppSettingsHasKeyStringTrue()
        {
            var dictionary = new Dictionary<string, object>();
            var settings = new HoldemAppSettings(dictionary);

            settings.Set(SAVE_CONFIG_KEY_DIR, SaveDirectoryValue());

            var hasKey = settings.ContainsKey(SAVE_CONFIG_KEY_DIR);

            Assert.AreEqual(true, hasKey);
        }

        [Test]
        public void HoldemAppSettingsHasKeyFalse()
        {
            var dictionary = new Dictionary<string, object>();
            var settings = new HoldemAppSettings(dictionary);

            var hasKey = settings.ContainsKey(ConfigKey.Invalid);

            Assert.AreEqual(false, hasKey);
        }

        [Test]
        public void HoldemAppSettingsClear()
        {
            var dictionary = new Dictionary<string, object>();
            var settings = new HoldemAppSettings(dictionary);

            settings.Set(SAVE_CONFIG_KEY_DIR, SaveDirectoryValue());

            settings.Clear();

            var hasKey = settings.ContainsKey(SAVE_CONFIG_KEY_DIR);

            Assert.False(hasKey);
        }

        #endregion  //HoldemAppSettings
    }
}